//
//  sanFanYuanViewController.m
//  3FSports
//
//  Created by mac on 16/11/15.
//  Copyright © 2016年 sanAiFuSport.com. All rights reserved.
//

#import "sanFanYuanViewController.h"
#import "DOPDropDownMenu.h"
#import "Masonry.h"

// cell的重用标识符
static NSString *cellId = @"cellId";
@interface sanFanYuanViewController ()<DOPDropDownMenuDataSource,DOPDropDownMenuDelegate,UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) NSArray *classifys;
@property (nonatomic, strong) NSArray *cates;
@property (nonatomic, strong) NSArray *movices;
@property (nonatomic, strong) NSArray *hostels;
@property (nonatomic, strong) NSArray *areas;

@property (nonatomic, strong) NSArray *sorts;
@property (nonatomic, weak) DOPDropDownMenu *menu;

@end

@implementation sanFanYuanViewController

- (void)viewDidLoad {
    
    [self setupUI];

}
#pragma mark-- 搭建界面
- (void)setupUI
{
    
    self.view.backgroundColor = [UIColor orangeColor];
    
    self.title = @"雪场附近房源";
    
    //数据
    self.classifys = @[@"万龙滑雪场",@"温榆河滑雪场",@"北海道滑雪场",@"八达岭滑雪场"];
    
    self.areas = @[@"官方推荐",@"距离优先",@"价格优先"];
    
    self.sorts = @[@"更多筛选",@"亲子半价",@"团购半价"];
    
    //添加菜单
    DOPDropDownMenu *menu = [[DOPDropDownMenu alloc]initWithOrigin:CGPointMake(0, 64) andHeight:44];
    
    menu.delegate = self;
    menu.dataSource = self;
    [self.view addSubview:menu];
    
    _menu = menu;
    [menu selectDefalutIndexPath];
    
    // MARK: - 1.左侧的分类列表视图
    UITableView *tvCategory = [[UITableView alloc] init];
    
    [self.view addSubview:tvCategory];
    
    [tvCategory mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.view).offset(108);
        make.left.equalTo(self.view);
        make.width.mas_equalTo(90);
        make.bottom.equalTo(self.view);
        
    }];
    //2 侧有视图
    UITableView *tvRight = [[UITableView alloc]init];
    [self.view addSubview:tvRight];
    
    [tvRight mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.bottom.equalTo(tvCategory);
        make.right.equalTo(self.view);
        make.left.equalTo(tvCategory.mas_right);

    }];
    
    // MARK: -----设置列表的属性-------
    // 1.设置数据源和代理对象
    tvCategory.dataSource = self;
    tvCategory.delegate = self;
    
    tvRight.dataSource = self;
    tvRight.delegate = self;
    
    //注册Cell
    [tvCategory registerClass:[UITableViewCell class] forCellReuseIdentifier:cellId];
    [tvRight registerClass:[UITableViewCell class] forCellReuseIdentifier:cellId];
    
    //不显示多余的行数
    tvCategory.tableFooterView = [[UIView alloc]init];
    tvRight.tableFooterView = [[UIView alloc]init];
    
    //隐藏指示条
    tvCategory.showsVerticalScrollIndicator = NO;
    tvRight.showsVerticalScrollIndicator = NO;
    
    //设置一下行高
    tvCategory.rowHeight = 40;
    
    //设置预估的行高
    tvRight.rowHeight = 120;
    //tvRight.estimatedRowHeight = 120;
    //tvRight.rowHeight = UITableViewAutomaticDimension;
    

    
    
}
#pragma mark-- 实现数据源方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 10;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];
    
    cell.textLabel.text = @(indexPath.row).description;
    
    return cell;
}

#pragma mark - Table view data source


- (void)menuReloadData
{
    self.classifys = @[@"万龙滑雪场",@"温榆河滑雪场",@"北海道滑雪场"];
    [_menu reloadData];
}

- (NSInteger)numberOfColumnsInMenu:(DOPDropDownMenu *)menu
{
    return 3;
}

- (NSInteger)menu:(DOPDropDownMenu *)menu numberOfRowsInColumn:(NSInteger)column
{
    if (column == 0) {
        return self.classifys.count;
    }else if (column == 1){
        return self.areas.count;
    }else {
        return self.sorts.count;
    }
}

- (NSString *)menu:(DOPDropDownMenu *)menu titleForRowAtIndexPath:(DOPIndexPath *)indexPath
{
    if (indexPath.column == 0) {
        return self.classifys[indexPath.row];
    } else if (indexPath.column == 1){
        return self.areas[indexPath.row];
    } else {
        return self.sorts[indexPath.row];
    }
}

// new datasource

- (NSString *)menu:(DOPDropDownMenu *)menu imageNameForRowAtIndexPath:(DOPIndexPath *)indexPath
{
    if (indexPath.column == 0 || indexPath.column == 1) {
        return [NSString stringWithFormat:@"ic_filter_category_%ld",indexPath.row];
    }
    return nil;
}

- (NSString *)menu:(DOPDropDownMenu *)menu imageNameForItemsInRowAtIndexPath:(DOPIndexPath *)indexPath
{
    if (indexPath.column == 0 && indexPath.item >= 0) {
        return [NSString stringWithFormat:@"ic_filter_category_%ld",indexPath.item];
    }
    return nil;
}

// new datasource

- (NSString *)menu:(DOPDropDownMenu *)menu detailTextForRowAtIndexPath:(DOPIndexPath *)indexPath
{
    if (indexPath.column < 2) {
        return [@(arc4random()%1000) stringValue];
    }
    return nil;
}

- (NSString *)menu:(DOPDropDownMenu *)menu detailTextForItemsInRowAtIndexPath:(DOPIndexPath *)indexPath
{
    return [@(arc4random()%1000) stringValue];
}

- (NSInteger)menu:(DOPDropDownMenu *)menu numberOfItemsInRow:(NSInteger)row column:(NSInteger)column
{
    if (column == 0) {
        if (row == 0) {
            return self.cates.count;
        } else if (row == 2){
            return self.movices.count;
        } else if (row == 3){
            return self.hostels.count;
        }
    }
    return 0;
}

- (NSString *)menu:(DOPDropDownMenu *)menu titleForItemsInRowAtIndexPath:(DOPIndexPath *)indexPath
{
    if (indexPath.column == 0) {
        if (indexPath.row == 0) {
            return self.cates[indexPath.item];
        } else if (indexPath.row == 2){
            return self.movices[indexPath.item];
        } else if (indexPath.row == 3){
            return self.hostels[indexPath.item];
        }
    }
    return nil;
}


@end
